<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="../react@18.js"></script>
<script src="../react-dom@18.js"></script>
<script src="../babel.js"></script>
<script type="text/babel">
    class App extends React.Component {
        state = {
            num: 0,
            name:"张三",
            age:19
        }
        render() {
            console.log("哈哈哈")
            /* 
            在react18中无论在合成事件还是原生事件中this.setState的更新都是异步的，都会将多个this.setState合并更新渲染一次。
            */
            return (
                <div>
                    <h1>{this.state.num}---{this.state.name}-----{this.state.age}</h1>
                    <button onClick={() => {
                        // this.setState({
                        //     num:10
                        // })
                        // console.log(this.state.num)
                        setTimeout(() => {
                            this.setState({
                                num: 10
                            })
                            console.log(this.state.num)
                        })
                    }}>+10</button>
                    <button onClick={()=>{
                        // this.setState({
                        //     num:100
                        // })
                        // this.setState({
                        //     age:10
                        // })
                        // this.setState({
                        //     name:"李四"
                        // })
                        setTimeout(()=>{
                            this.setState({
                            num:100
                        })
                        this.setState({
                            age:10
                        })
                        this.setState({
                            name:"李四"
                        })
                        })
                    }}>改变</button>
                </div>
            )
        }
    }
    let root = ReactDOM.createRoot(document.getElementById("root"));
    root.render(<App />)
</script>

</html>